Skip to content

Conversation

@tiangolo
Copy link

@tiangolo tiangolo commented Dec 3, 2023

🔊 Add info about one reason for RuntimeError, which is otherwise difficult to catch

When there's a multiline error message in an assert, insert_assert can't find the frame, probably a quirk of Python. This adds a message showing what might be the problem.

Here's an example test that breaks with the RuntimeError:

def test_multiline_error_message(insert_assert):
    assert True, (
        "This error message has "
        "more than one line."
    )
    insert_assert(1)

The new error will show:

RuntimeError: insert_assert() was unable to find the frame from which it was called.

Sometimes this happens when there's an assert statement with a an error message with multiple lines, like: 

assert foo == bar, (
    'foo should be '
    'equal to bar'
)

You can try commenting out that assert statement while you run insert_assert() and then uncommenting it afterwards.

insert_assert was called with:
1

@codecov
Copy link

codecov bot commented Dec 3, 2023

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.29%. Comparing base (ec406ff) to head (af33c65).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #149   +/-   ##
=======================================
  Coverage   96.29%   96.29%           
=======================================
  Files           8        8           
  Lines         729      729           
  Branches      111      111           
=======================================
  Hits          702      702           
  Misses         21       21           
  Partials        6        6           
Files with missing lines Coverage Δ
devtools/pytest_plugin.py 88.13% <ø> (ø)

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ec406ff...af33c65. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tiangolo tiangolo closed this by deleting the head repository Nov 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant